package com.yxw.yx_hotel.service.impl;

import cn.hutool.core.bean.BeanUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.yxw.yx_hotel.dto.AddStayInDTO;
import com.yxw.yx_hotel.dto.AddStayWaitDto;
import com.yxw.yx_hotel.dto.QueryStayRecordDto;
import com.yxw.yx_hotel.dto.QueryStayWaitDto;
import com.yxw.yx_hotel.entity.*;
import com.yxw.yx_hotel.excel.ExportStayWaitExcel;
import com.yxw.yx_hotel.mapper.*;
import com.yxw.yx_hotel.service.StayWaitService;
import com.yxw.yx_hotel.utils.PageUtils;
import com.yxw.yx_hotel.utils.UserUtil;
import com.yxw.yx_hotel.vo.StayRecordVo;
import com.yxw.yx_hotel.vo.StayWaitVo;
import com.yxw.yx_hotel.vo.UserTokenVo;
import com.yxw.yxnet_cd_center.common.dto.PageVO;
import com.yxw.yxnet_cd_center.common.exception.BaseException;
import com.yxw.yxnet_cd_center.common.utils.BaseResult;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.regex.Pattern;

/**
 *  待住管理
 * @author liuxin
 * @date 2024.01.18
 */
@Slf4j
@Service
public class StayWaitServiceImpl extends ServiceImpl<StayWaitMapper, YxStayWaitEntity> implements StayWaitService {

    @Autowired
    private UserUtil  userUtil;

    @Autowired
    private StayRecordMapper stayRecordMapper;

    @Autowired
    private StayInMapper  stayInMapper;

    @Autowired
    private PostMapper postMapper;

    @Autowired
    private DeptMapper deptMapper;

    @Autowired
    private RoomMapper roomMapper;

    @Autowired
    private RoomBedMapper  roomBedMapper;
    /**
     * 新增待住名单
     * @param dto
     */
    @Override
    @Transactional(rollbackFor=Exception.class)
    public void addStayWait(AddStayWaitDto dto){
        UserTokenVo userVo = userUtil.getLoginUserVo();
        LambdaQueryWrapper<YxRoomBedEntity> bedWrapper=new LambdaQueryWrapper();
        bedWrapper.eq(YxRoomBedEntity::getRoomId,dto.getRoomId());
        bedWrapper.eq(YxRoomBedEntity::getTenantId,userVo.getTenantId());
        bedWrapper.eq(YxRoomBedEntity::getBedId,dto.getBedId());
        YxRoomBedEntity bedEntity = roomBedMapper.selectOne(bedWrapper);
        if(bedEntity.getStatus() < 2)
        {
            throw new BaseException(bedEntity.getBedName()+ "已经有人入住,新增失败");
        } 
        YxRoomEntity roomEntity = roomMapper.selectById(dto.getRoomId());
        if(null==roomEntity){
            throw new BaseException("未查询到宿舍信息");
        }
        if(roomEntity.getStatus().intValue() == 0){
            throw new BaseException("宿舍处于维修状态，不能住人");
        }
        YxStayWaitEntity entity = new YxStayWaitEntity();
        BeanUtil.copyProperties(dto,entity);
        entity.setCreateTime(new Date());
        entity.setCreateName(userVo.getNickName());
        entity.setTenantId(userVo.getTenantId());
        entity.setCreateId(userVo.getUserId());
        entity.setStatus(0);
        //更新待住状态
        LambdaUpdateWrapper<YxRoomBedEntity> updateWrapper=new LambdaUpdateWrapper();
        updateWrapper.eq(YxRoomBedEntity::getBedId,dto.getBedId());
        updateWrapper.set(YxRoomBedEntity::getStatus,0);
        roomBedMapper.update(null, updateWrapper);
        baseMapper.insert(entity);
        
    }

    /**
     * 查询宿舍资产列表
     * @param dto
     * @return
     */
    @Override
    public PageVO<StayWaitVo> pageStayWaitList(QueryStayWaitDto dto){
        List<StayWaitVo> voList=new ArrayList<>();
        UserTokenVo userVo = userUtil.getLoginUserVo();
        Page<YxStayWaitEntity> page = new Page<>(dto.getCurrPage(),dto.getPageSize());
        LambdaQueryWrapper<YxStayWaitEntity> queryWrapper=new LambdaQueryWrapper();
        if(StringUtils.isNotBlank(dto.getUserName())){
            queryWrapper.like(YxStayWaitEntity::getUserName,dto.getUserName().trim());
        }
        if(StringUtils.isNotBlank(dto.getDeptName())){
            queryWrapper.like(YxStayWaitEntity::getDeptName,dto.getDeptName().trim());
        }
        if(StringUtils.isNotBlank(dto.getRoomName())){
            queryWrapper.like(YxStayWaitEntity::getRoomName,dto.getRoomName().trim());
        }
        if(null != dto.getUserState()){
            if(dto.getUserState() >= 0 && dto.getUserState() < 4)
            {
                queryWrapper.eq(YxStayWaitEntity::getUserState,dto.getUserState());
            }
        }
        queryWrapper.ge(null!=dto.getCreateStartTime(),YxStayWaitEntity::getCreateTime,dto.getCreateStartTime());
        queryWrapper.le(null!=dto.getCreateEndTime(),YxStayWaitEntity::getCreateTime,dto.getCreateEndTime());
        queryWrapper.eq(YxStayWaitEntity::getTenantId,userVo.getTenantId());
        queryWrapper.eq(YxStayWaitEntity::getStatus,0);
        queryWrapper.orderByDesc(YxStayWaitEntity::getCreateTime);
        Page<YxStayWaitEntity> entityPage = baseMapper.selectPage(page, queryWrapper);
        List<YxStayWaitEntity> records = entityPage.getRecords();
        if(null!=records && !records.isEmpty()){
            voList=BeanUtil.copyToList(records,StayWaitVo.class);
        }
        return PageUtils.get(page, voList);
    }

    /**
     * 查询待住详情
     * @param stayWaitId
     * @return
     */
    @Override
    public StayWaitVo getStayWaitById(Long stayWaitId) {
        StayWaitVo vo = new StayWaitVo();
        YxStayWaitEntity entity = baseMapper.selectById(stayWaitId);
        if(null!=entity){
            BeanUtil.copyProperties(entity,vo);
        }
        return vo;
    }

    /**
     * 更新待住信息
     * @param dto
     */
    @Override
    @Transactional(rollbackFor=Exception.class)
    public void updateStayWait(AddStayWaitDto dto){
        if(null==dto.getStayWaitId()){
            throw new BaseException("待住ID不能为空");
        }
        UserTokenVo userVo = userUtil.getLoginUserVo();
        YxStayWaitEntity entity = baseMapper.selectById(dto.getStayWaitId());
        if(null==entity){
            throw new BaseException("未查询到待住记录进行修改");
        }
        if(!dto.getBedId().equals(entity.getBedId())){
            if(!dto.getRoomId().equals(entity.getRoomId())){
                YxRoomEntity roomEntity = roomMapper.selectById(dto.getRoomId());
                if(null==roomEntity){
                    throw new BaseException("未查询到宿舍信息");
                }
                if(roomEntity.getStatus().intValue() == 0){
                    throw new BaseException("宿舍处于维修状态，不能住人");
                }  
            }
            LambdaQueryWrapper<YxRoomBedEntity> bedWrapper=new LambdaQueryWrapper();
            bedWrapper.eq(YxRoomBedEntity::getRoomId,dto.getRoomId());
            bedWrapper.eq(YxRoomBedEntity::getTenantId,userVo.getTenantId());
            bedWrapper.eq(YxRoomBedEntity::getBedId,dto.getBedId());
            YxRoomBedEntity bedEntity = roomBedMapper.selectOne(bedWrapper);
            if(bedEntity.getStatus() < 2)
            {
                throw new BaseException(bedEntity.getBedName()+ "已经有人入住,修改失败");
            }
        }
        BeanUtil.copyProperties(dto,entity);
        entity.setUpdateId(userVo.getUserId());
        entity.setUpdateName(userVo.getNickName());
        entity.setUpdateTime(new Date());
        baseMapper.updateById(entity);
    }

    /**
     * 查询待住名单列表（不分页）
     * @param dto
     * @return
     */
    @Override
    public List<StayWaitVo> getStayWaitList(QueryStayWaitDto dto) {
        List<StayWaitVo> voList=new ArrayList<>();
        UserTokenVo userVo = userUtil.getLoginUserVo();
        LambdaQueryWrapper<YxStayWaitEntity> queryWrapper=new LambdaQueryWrapper();
        if(StringUtils.isNotBlank(dto.getUserName())){
            queryWrapper.like(YxStayWaitEntity::getUserName,dto.getUserName().trim());
        }
        if(StringUtils.isNotBlank(dto.getDeptName())){
            queryWrapper.like(YxStayWaitEntity::getDeptName,dto.getDeptName().trim());
        }
        if(StringUtils.isNotBlank(dto.getRoomName())){
            queryWrapper.like(YxStayWaitEntity::getRoomName,dto.getRoomName().trim());
        }
        queryWrapper.ge(null!=dto.getCreateStartTime(),YxStayWaitEntity::getCreateTime,dto.getCreateStartTime());
        queryWrapper.le(null!=dto.getCreateEndTime(),YxStayWaitEntity::getCreateTime,dto.getCreateEndTime());
        queryWrapper.eq(YxStayWaitEntity::getTenantId,userVo.getTenantId());
        queryWrapper.eq(YxStayWaitEntity::getStatus,0);
        queryWrapper.orderByDesc(YxStayWaitEntity::getCreateTime);
        Integer cnt = baseMapper.selectCount(queryWrapper);
        if(cnt>20000){
            throw new BaseException("一次性导出不能超过两万条数据,请导出缩小范围");
        }
        List<YxStayWaitEntity> entityList = baseMapper.selectList(queryWrapper);
        if(null!=entityList && !entityList.isEmpty()){
            voList=BeanUtil.copyToList(entityList,StayWaitVo.class);
        }
        return voList;
    }

    /**
     * 办理入住
     * @param stayWaitIds
     */
    @Override
    @Transactional(rollbackFor=Exception.class)
    public void addStayIn(AddStayInDTO addStayInDTO) {
        
        List<Long> stayWaitIds = addStayInDTO.getStayWaitIds();
        UserTokenVo userVo = userUtil.getLoginUserVo();
        if(null==stayWaitIds || stayWaitIds.isEmpty()){
            throw new BaseException("请选择入住名单");
        }
        //查询待住信息
        LambdaQueryWrapper<YxStayWaitEntity> queryWrapper=new LambdaQueryWrapper();
        queryWrapper.eq(YxStayWaitEntity::getStatus,0);
        queryWrapper.in(YxStayWaitEntity::getStayWaitId,stayWaitIds);
        List<YxStayWaitEntity> waitEntityList = baseMapper.selectList(queryWrapper);
        if(null==waitEntityList || waitEntityList.isEmpty()){
            throw new BaseException("未查询到待住信息");
        }
        List<Long> bedIds = new ArrayList();
        for(YxStayWaitEntity oYxStayWaitEntity : waitEntityList)
        {
            oYxStayWaitEntity.setNote(addStayInDTO.getNote());
            bedIds.add(oYxStayWaitEntity.getBedId());
        }
        //批量新增在住信息
        stayInMapper.insertByBatch(waitEntityList,userVo);
        //新增入住/取消入住的记录
        stayRecordMapper.insertByBatch(waitEntityList,1,userVo);
        //更新待住状态
        LambdaUpdateWrapper<YxStayWaitEntity> updateWrapper=new LambdaUpdateWrapper();
        updateWrapper.set(YxStayWaitEntity::getStatus,1);
        updateWrapper.set(YxStayWaitEntity::getUpdateId,userVo.getUserId());
        updateWrapper.set(YxStayWaitEntity::getUpdateName,userVo.getNickName());
        updateWrapper.set(YxStayWaitEntity::getUpdateTime,new Date());
        updateWrapper.in(YxStayWaitEntity::getStayWaitId,stayWaitIds);
        baseMapper.update(null,updateWrapper);
         //更新待住状态
        LambdaUpdateWrapper<YxRoomBedEntity> updateBedWrapper=new LambdaUpdateWrapper();
        updateBedWrapper.in(YxRoomBedEntity::getBedId,bedIds);
        updateBedWrapper.set(YxRoomBedEntity::getStatus,1);
        roomBedMapper.update(null, updateBedWrapper);
    }

    /**
     * 取消待住
     * @param stayWaitIds
     */
    @Override
    @Transactional(rollbackFor=Exception.class)
    public void cancelStayWait(List<Long> stayWaitIds) {
        UserTokenVo userVo = userUtil.getLoginUserVo();
        if(null==stayWaitIds || stayWaitIds.isEmpty()){
            throw new BaseException("请选择需要取消的待住名单");
        }
        //查询待住信息
        LambdaQueryWrapper<YxStayWaitEntity> queryWrapper=new LambdaQueryWrapper();
        queryWrapper.eq(YxStayWaitEntity::getStatus,0);
        queryWrapper.in(YxStayWaitEntity::getStayWaitId,stayWaitIds);
        List<YxStayWaitEntity> waitEntityList = baseMapper.selectList(queryWrapper);
        if(null==waitEntityList || waitEntityList.isEmpty()){
            throw new BaseException("未查询到待住信息");
        }
        List<Long> bedIds = new ArrayList();
        for(YxStayWaitEntity oYxStayWaitEntity : waitEntityList)
        {
            bedIds.add(oYxStayWaitEntity.getBedId());
        }        
        //新增入住/取消入住的记录
        stayRecordMapper.insertByBatch(waitEntityList,0,userVo);
        //更新待住状态
        LambdaUpdateWrapper<YxStayWaitEntity> updateWrapper=new LambdaUpdateWrapper();
        updateWrapper.set(YxStayWaitEntity::getStatus,2);
        updateWrapper.set(YxStayWaitEntity::getUpdateId,userVo.getUserId());
        updateWrapper.set(YxStayWaitEntity::getUpdateName,userVo.getNickName());
        updateWrapper.set(YxStayWaitEntity::getUpdateTime,new Date());
        updateWrapper.in(YxStayWaitEntity::getStayWaitId,stayWaitIds);
        baseMapper.update(null,updateWrapper);
        //更新床位待住状态
        LambdaUpdateWrapper<YxRoomBedEntity> updateBedWrapper=new LambdaUpdateWrapper();
        updateBedWrapper.in(YxRoomBedEntity::getBedId,bedIds);
        updateBedWrapper.set(YxRoomBedEntity::getStatus,2);
        roomBedMapper.update(null, updateBedWrapper);
    }

    /**
     * 导入待住数据
     * @param dataList
     */
    @Override
    @Transactional(rollbackFor=Exception.class)
    public BaseResult importData(List<ExportStayWaitExcel> dataList) {
        List<YxStayWaitEntity> entityList=new ArrayList<>();
        String errMsg=this.validataExcel(dataList,entityList);
        if(StringUtils.isNotBlank(errMsg)){
            return BaseResult.failed("201",errMsg);
        }
        for (YxStayWaitEntity entity:entityList) {
            baseMapper.insert(entity);
        }
        log.info("导入数据成功,总共导入{}条数据",dataList.size());
        return BaseResult.doSuccess(null,"导入成功");
    }

    /**
     * 查询入住历史(记录)列表
     * @param dto
     * @return
     */
    @Override
    public PageVO<StayRecordVo> pageStayRecordList(QueryStayRecordDto dto) {
        List<StayRecordVo> voList=new ArrayList<>();
        UserTokenVo userVo = userUtil.getLoginUserVo();
        Page<YxStayRecordEntity> page = new Page<>(dto.getCurrPage(),dto.getPageSize());
        LambdaQueryWrapper<YxStayRecordEntity> queryWrapper=new LambdaQueryWrapper();
        if(StringUtils.isNotBlank(dto.getUserName())){
            queryWrapper.like(YxStayRecordEntity::getUserName,dto.getUserName().trim());
        }
        if(StringUtils.isNotBlank(dto.getDeptName())){
            queryWrapper.like(YxStayRecordEntity::getDeptName,dto.getDeptName().trim());
        }
        if(StringUtils.isNotBlank(dto.getRoomName())){
            queryWrapper.like(YxStayRecordEntity::getRoomName,dto.getRoomName().trim());
        }
        queryWrapper.ge(null!=dto.getStayTimeStart(),YxStayRecordEntity::getStayTime,dto.getStayTimeStart());
        queryWrapper.le(null!=dto.getStayTimeEnd(),YxStayRecordEntity::getStayTime,dto.getStayTimeEnd());
        queryWrapper.ge(null!=dto.getCreateTimeStart(),YxStayRecordEntity::getCreateTime,dto.getCreateTimeStart());
        queryWrapper.le(null!=dto.getCreateTimeEnd(),YxStayRecordEntity::getCreateTime,dto.getCreateTimeEnd());
        queryWrapper.eq(YxStayRecordEntity::getTenantId,userVo.getTenantId());
        queryWrapper.eq(null!=dto.getStatus(),YxStayRecordEntity::getStatus,dto.getStatus());
        queryWrapper.eq(null!=dto.getUserState(),YxStayRecordEntity::getUserState,dto.getUserState());
        queryWrapper.orderByDesc(YxStayRecordEntity::getCreateTime);
        Page<YxStayRecordEntity> pageEntity = stayRecordMapper.selectPage(page, queryWrapper);
        List<YxStayRecordEntity> entityList = pageEntity.getRecords();
        if(null!=entityList && !entityList.isEmpty()){
            voList=BeanUtil.copyToList(entityList,StayRecordVo.class);
        }
        return PageUtils.get(page, voList);
    }
    //-------------------------------------------------------------------------------------------------------------------------------------

    /**
     * excel导出校验
     * @param dataList
     */
    private String validataExcel(List<ExportStayWaitExcel> dataList,List<YxStayWaitEntity> entityList){
        UserTokenVo userVo = userUtil.getLoginUserVo();
        Long tenantId = userVo.getTenantId();
        StringBuffer sbf=new StringBuffer();
        for (int i = 0; i < dataList.size(); i++) {
            ExportStayWaitExcel excelEntity = dataList.get(i);
            YxStayWaitEntity entity = new YxStayWaitEntity();
            BeanUtil.copyProperties(excelEntity,entity);
            String userName = excelEntity.getUserName();
            if(StringUtils.isBlank(userName)){
                sbf.append("第"+(i+3)+"行员工姓名不能为空</br>");
            }
            String userNum = excelEntity.getUserNum();
            if(StringUtils.isBlank(userNum)){
                sbf.append("第"+(i+3)+"行员工工号不能为空</br>");
            }
            String sex = excelEntity.getSexName();
            if(StringUtils.isBlank(sex) || (!"男".equals(sex) && !"女".equals(sex))){
                sbf.append("第"+(i+3)+"行性别不能为空并且只能选男/女</br>");
            }else{
                entity.setSex("女".equals(sex)?0:1);
            }
            String phone = excelEntity.getPhone();
            Pattern pattern = Pattern.compile("^1[0-9]{10}$");
            if(StringUtils.isBlank(phone) || !pattern.matcher(phone).matches()){
                sbf.append("第"+(i+3)+"行手机号不能为空并且是11位正确手机格式</br>");
            }
            String idCard = excelEntity.getIdCard();
            Pattern patternCard = Pattern.compile("^\\d{17}[0-9Xx]$");
            if(StringUtils.isBlank(phone) || !patternCard.matcher(idCard).matches()){
                sbf.append("第"+(i+3)+"行身份证不能为空并且需要正确格式</br>");
            }
            String postName = excelEntity.getPostName();
            if(StringUtils.isBlank(postName)){
                sbf.append("第"+(i+3)+"行岗位不能为空</br>");
            }else{
                LambdaQueryWrapper<YxCsPostEntity> postWrapper=new LambdaQueryWrapper();
                postWrapper.eq(YxCsPostEntity::getPostName,postName);
                postWrapper.eq(YxCsPostEntity::getTenantId,tenantId);
                List<YxCsPostEntity> yxCsPostEntities = postMapper.selectList(postWrapper);
                if(null==yxCsPostEntities || yxCsPostEntities.size()!=1){
                    sbf.append("第"+(i+3)+"行岗位名称【"+postName+"】不存在或者存在多条,请检查岗位信息</br>");
                }else{
                    entity.setPostId(yxCsPostEntities.get(0).getPostId());
                    entity.setPostName(yxCsPostEntities.get(0).getPostName());
                }
            }
            String deptName = excelEntity.getDeptName();
            if(StringUtils.isBlank(deptName)){
                sbf.append("第"+(i+3)+"行所属部门不能为空</br>");
            }else{
                LambdaQueryWrapper<YxCsDeptEntity> deptWrapper=new LambdaQueryWrapper();
                deptWrapper.eq(YxCsDeptEntity::getDeptName,deptName);
                deptWrapper.eq(YxCsDeptEntity::getTenantId,tenantId);
                List<YxCsDeptEntity> deptEntities = deptMapper.selectList(deptWrapper);
                if(null==deptEntities || deptEntities.size()!=1){
                    sbf.append("第"+(i+3)+"行所属部门【"+deptName+"】不存在或者存在多条,请检查部门信息</br>");
                }else{
                    entity.setDeptId(deptEntities.get(0).getDeptId());
                    entity.setDeptName(deptEntities.get(0).getDeptName());
                }
            }
            //员工状态 1：实习 2：正式 3：临时
            String userStateName = excelEntity.getUserStateName();
            if(StringUtils.isBlank(userStateName) || (!"实习".equals(userStateName) && !"正式".equals(userStateName) && !"临时".equals(userStateName))){
                sbf.append("第"+(i+3)+"行员工状态不能为空并且必须是实习/正式/临时</br>");
            }else{
                if("实习".equals(userStateName) ){
                    entity.setUserState(1);
                } else if("正式".equals(userStateName) ){
                    entity.setUserState(2);
                } else{
                    entity.setUserState(3);
                }
            }
            if(StringUtils.isBlank(excelEntity.getStayTime())){
                sbf.append("第"+(i+3)+"行入住时间不能为空</br>");
            }
            String roomName = excelEntity.getRoomName();
            if(StringUtils.isNotBlank(roomName)){
                LambdaQueryWrapper<YxRoomEntity> broomWrapper=new LambdaQueryWrapper();
                broomWrapper.eq(YxRoomEntity::getRoomName,roomName);
                broomWrapper.eq(YxRoomEntity::getTenantId,tenantId);
                YxRoomEntity roomEntity = roomMapper.selectOne(broomWrapper);
                if(null==roomEntity){
                    sbf.append("第"+(i+3)+"行宿舍【"+roomName+"】不存在</br>");
                }else{
                    entity.setRoomId(roomEntity.getRoomId());
                    entity.setRoomName(roomEntity.getRoomName());
                    //校验宿舍
                    String bedRoom = excelEntity.getBedRoom();
                    if(StringUtils.isNotBlank(bedRoom)){
                        Long bedRoomTmp = null;
                        try{
                            bedRoomTmp = Long.valueOf(bedRoom);
                        }
                        catch(Exception e){
                            sbf.append("第"+(i+3)+"行床位号【"+bedRoom+"】不是数字类型</br>");
                            bedRoomTmp = null;
                        }
                        if(null != bedRoomTmp){
                            LambdaQueryWrapper<YxRoomBedEntity> bedWrapper=new LambdaQueryWrapper();
                            bedWrapper.eq(YxRoomBedEntity::getRoomId,roomEntity.getRoomId());
                            bedWrapper.eq(YxRoomBedEntity::getTenantId,tenantId);
                            bedWrapper.eq(YxRoomBedEntity::getBedId,bedRoomTmp);
                            YxRoomBedEntity bedEntity = roomBedMapper.selectOne(bedWrapper);
                            if(null==bedEntity){
                                sbf.append("第"+(i+3)+"行床位号【"+bedRoom+"】不存在</br>");
                            }else{
                                entity.setBedId(bedEntity.getBedId());
                                entity.setBedName(bedEntity.getBedName());
                            }
                        }
                    }
                }
            }
            String payStatusName = excelEntity.getPayStatusName();
            if(StringUtils.isNotBlank(payStatusName)){
                entity.setPayStatus("是".equals(payStatusName)?1:0);
            }
            entity.setCreateId(userVo.getUserId());
            entity.setCreateTime(new Date());
            entity.setCreateName(userVo.getNickName());
            entity.setTenantId(tenantId);
            entityList.add(entity);
        }
        return sbf.toString();
    }
}
